<template>
  <div>
    <el-form style="margin: 0 auto;width: 500px">
      <el-form-item label="用户名">
        <el-input v-model="ruleForm.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="ruleForm.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 100%" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        username: 'xc'
      }
    }
  },
  methods: {
    async login() {
      await this.$store.dispatch('user/login', { username: this.ruleForm.username })
      await this.$store.dispatch('user/getInfo')
      this.$router.replace({
        path: '/'
      })
    }
  }
}
</script>
